package cn.dgiot.fd.controller;

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.iot.model.v20180120.CreateThingModelResponse;
import com.aliyuncs.iot.model.v20180120.DeleteThingModelResponse;
import com.aliyuncs.iot.model.v20180120.PublishThingModelResponse;
import com.aliyuncs.iot.model.v20180120.QueryThingModelResponse;
import com.aliyuncs.iot.model.v20180120.UpdateThingModelResponse;

import cn.dgiot.fd.model.ThingModel;
import cn.dgiot.fd.service.IThingModelService;

/**
 * [服务消息相关]
 * @author
 *
 */
@RestController
@RequestMapping("/thingModel")
public class ThingModelController {

	private Logger logger = LoggerFactory.getLogger(ThingModelController.class);
	
	@Autowired
	private IThingModelService thingModelService;
	
	/**
	 * [创建消息消费组]
	 * @param thingModel
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/createDefaultThingModel")
	public String createDefaultThingModel(@RequestBody ThingModel thingModel,HttpServletResponse response) throws Exception {
		CreateThingModelResponse createThingModelResponse = thingModelService.createDefaultThingModel(thingModel);
		return JSON.toJSONString(createThingModelResponse);
	}
	
	/**
	 * [创建消息消费组]
	 * @param thingModel
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/updateDefaultThingModel")
	public String updateDefaultThingModel(@RequestBody ThingModel thingModel,HttpServletResponse response) throws Exception {
		UpdateThingModelResponse updateThingModelResponse = thingModelService.updateDefaultThingModel(thingModel);
		return JSON.toJSONString(updateThingModelResponse);
	}
	
	/**
	 * [查询物模信息]
	 * @param thingModel
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/queryThingModel")
	public String queryThingModel(@RequestBody ThingModel thingModel,HttpServletResponse response) throws Exception {
		QueryThingModelResponse queryThingModelResponse = thingModelService.queryThingModel(thingModel);
		return JSON.toJSONString(queryThingModelResponse);
	}
	
	/**
	 * [发布指定产品的物模型]
	 * @param thingModel
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/publishThingModel")
	public String publishThingModel(@RequestBody ThingModel thingModel,HttpServletResponse response) throws Exception {
		PublishThingModelResponse  publishThingModelResponse = thingModelService.publishThingModel(thingModel);
		return JSON.toJSONString(publishThingModelResponse);
	}
	
	/**
	 * [删除物模型]
	 * @param thingModel
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/deleteDefaultThingModel")
	public String deleteDefaultThingModel(@RequestBody ThingModel thingModel,HttpServletResponse response) throws Exception {
		DeleteThingModelResponse  deleteThingModelResponse = thingModelService.deleteDefaultThingModel(thingModel);
		return JSON.toJSONString(deleteThingModelResponse);
	}
	
	/**
	 * [删除物模型]
	 * @param thingModel
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/refreshDefaultThingModel")
	public String refreshDefaultThingModel(@RequestBody ThingModel thingModel,HttpServletResponse response) throws Exception {
		PublishThingModelResponse  publishThingModelResponse = thingModelService.refreshDefaultThingModel(thingModel);
		return JSON.toJSONString(publishThingModelResponse);
	}

}